<?php
require_once 'init.php';
$phpmongo = new Phpmongo();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/common.js"></script>
<title>PhpMongo</title>
</head>
<body>
<div class="warp_left">
<?php
require_once 'left.php';
?>	
</div>
<div class="warp_right">
<?php
$dbInfo = $phpmongo->databaseInfo();
?>
	<div>
		<div>
			<form action="db.php" method="POST" onsubmit="return check();">
				<table>
					<tr>
						<td><b>Create new database</b></td>
					</tr>
					<tr>
						<td>New database:<input type="text" name="db" id="db" /></td>
						<td>
						<input type="hidden" name="act" value="createdb" />
						<input type="submit" value="Create Database" class="submit" />
						</td>
					</tr>
				</table>
			</form>
<script type="text/javascript">
function check(){
	var db = document.getElementById('db').value;
	db = trim(db);
	if(db == ''){
		alert("please input db name");
		document.getElementById('db').value = '';
		document.getElementById('db').focus();
		return false;
	}
}
</script>			
		</div>
		<br /><br /><br />
		<table class="table_info">
			<tr class="mingxi_table_thead">
				<th colspan="8">Database Info</th>
			</tr>
			<tr>
				<th>DB Name</th>
				<th>Collections</th>
				<th>DataSize</th>
				<th>StorageSize</th>
				<th>NumExtents</th>
				<th>Indexes</th>
				<th>IndexSize</th>
				<th>Ok</th>
			</tr>
			<?php
			foreach ($dbInfo as $info){
				echo'
			<tr>
				<td><a href="db.php?db='.$info['name'].'" 
				onclick="window.parent.frames[\'mongo_left\'].location=\'left.php?db='.$info['name'].'\'"
				>'.$info['name'].'</a>
				
				<div class="dbaction">
				<a href="db.php?db='.$info['name'].'" title="View"
				onclick="window.parent.frames[\'mongo_left\'].location=\'left.php?db='.$info['name'].'\'">
				<img src="images/ico-show.gif" />
				</a>
				<a href="db.php?act=dropDb&db='.$info['name'].'" title="delete" 
				onclick="return window.confirm(\'Caution:are you sure to drop database '.$info['name'].'?All data in the db will be losed!\');">
				<img src="images/ico-delete.gif" />
				</a>
				</div>
				</td>
				<td>'.$phpmongo->countCollection($info['name']).'</td>
				<td>'.$info['dataSize'].'</td>
				<td>'.$info['storageSize'].'</td>
				<td>'.$info['numExtents'].'</td>
				<td>'.$info['indexes'].'</td>
				<td>'.$info['indexSize'].'</td>
				<td>'.$info['ok'].'</td>
			</tr>	
				';
			}
			?>
		</table>	
		
		<br /><br /><br />
		<?php
		$mongo_info = ini_get_all("mongo"); 
		?>
		<table class="table_info">
			<tr class="mingxi_table_thead">
				<th colspan="4">Mongo Info</th>
			</tr>
			<tr>
				<th>Directive</th>
				<th>Global value</th>
				<th>Local value</th>
				<th>Access</th>
			</tr>
			<?php
			foreach ($mongo_info as $k => $info){
				echo'
			<tr>
				<td>'.$k.'</td>
				<td>'.$info['global_value'].'</td>
				<td>'.$info['local_value'].'</td>
				<td>'.$info['access'].'</td>
			</tr>	
				';
			}
			?>
		</table>		
		

	</div>

</div>

</body>
</html>